import router from '@/router'
import store from '@/store'
import config from '@/config/index'

console.log(config)
router.beforeEach(async (to, from, next) => {
  if (to.path != '/login') {
    if (!store.state.user.USearch || !store.state.user.USearch.uUser) {
      const USearchdata = await store.dispatch('user/GetSession')
      if (!USearchdata.uUser) {
        window.location.href = config.Relativepath + 'index.html'
      } else {
        // await store.dispatch('routes/setRoutes')

        // let accessRoutes = []
        // if (authentication === 'intelligence') {
        //     accessRoutes = await store.dispatch('routes/setRoutes')
        // } else if (authentication === 'all') {
        //     accessRoutes = await store.dispatch('routes/setAllRoutes')
        // }
        // accessRoutes.forEach((item) => {
        //     router.addRoute(item)
        // })

        next()
      }
    } else {
      next()
    }
  } else {
    next()
  }
})
